home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#18 (Mar 87)
/
Printer LSP sources
/
DumpTPrintStuff
next >
Wrap
Text File
|
1987-02-13
|
7KB
|
273 lines
UNIT DumpTPrint;
INTERFACE
USES
MacPrint, MyGlobals, StringFormat;
PROCEDURE PrintLine;
PROCEDURE PrintTab;
PROCEDURE PrintHex (n : LONGINT;
w : INTEGER);
PROCEDURE PrintInt (n : LONGINT);
PROCEDURE PrintString (s : Str255);
PROCEDURE PrintStrNum (s : Str255;
n : LONGINT);
PROCEDURE PrintStrHex (s : Str255;
n : LONGINT;
w : INTEGER);
PROCEDURE DumpEnum (msg : Str255;
val, resid : INTEGER);
PROCEDURE DumpRect (msg : Str255;
r : Rect);
PROCEDURE DumpPrInfo (msg : Str255;
prinf : TPrInfo);
PROCEDURE DumpPrXInfo (msg : Str255;
prxi : TPrXInfo);
PROCEDURE DumpPrStl (msg : Str255;
ps : TPrStl);
PROCEDURE DumpPrJob (msg : Str255;
pj : TPrJob);
PROCEDURE DumpPrintX (msg : Str255;
tpp : TPPrint);
PROCEDURE DumpPrint (msg : Str255;
hand : THPrint);
IMPLEMENTATION
{-----------Add a line to document-------------}
PROCEDURE PrintLine;
VAR
p : Ptr;
c : SignedByte;
BEGIN {this adds the line to end of the display}
p := @linebuff;
TEInsert(Pointer(ORD4(p) + 1), Length(linebuff), hTE);
c := Return;
TEInsert(@c, 1, hTE); { add CR }
WITH hTE^^ DO { Check to see if we're beyond bottom of page }
IF (lineHeight * nLines) > (viewRect.bottom - viewRect.top) THEN
TEScroll(0, -hTE^^.lineHeight, hTE); { scroll up one line }
linebuff := '';
END; {PrintLine}
{------------Formatting utilities----------------}
PROCEDURE PrintTab;
VAR
col, nexttab : INTEGER;
BEGIN { add spaces to next multiple of 8 }
col := Length(linebuff);
nexttab := col - INTEGER(BitAnd(col, 7)) + 8;
WHILE col < nexttab DO
BEGIN
col := col + 1;
IF col < 255 THEN
insert(' ', linebuff, col);
END;
END;
PROCEDURE PrintHex; {(n : LONGINT; w : INTEGER );}
BEGIN
SWriteHex(linebuff, n, w); { actual width }
END;
PROCEDURE PrintInt; {(n : LONGINT);}
BEGIN
SWriteInt(linebuff, n, 0); { minimum width }
END;
PROCEDURE PrintString; {(s : Str255);}
BEGIN
SWriteString(linebuff, s);
END;
PROCEDURE PrintStrNum; {(s : Str255; n : LONGINT );}
BEGIN { format a string and integer }
PrintTab;
SWriteString(linebuff, s);
SWriteInt(linebuff, n, 0); { minimum width }
END;
PROCEDURE PrintStrHex; {(s : Str255;n : LONGINT;w : INTEGER);}
BEGIN { format a string and hex }
PrintTab;
SWriteString(linebuff, s);
SWriteHex(linebuff, n, w);
END;
{ ------------- Format enumeration ------------ }
PROCEDURE DumpEnum; {(msg : Str255; val, resid : INTEGER);}
VAR
s : Str255;
rh : Handle;
limitp : WordPtr;
err : boolean;
BEGIN
err := TRUE;
PrintTab;
PrintString(msg);
rh := GetResource('STR#', resid);
IF (rh <> NIL) THEN { if we screwed up, don't try to format }
BEGIN
limitp := WordPtr(rh^); { number of strings }
IF (val >= 0) AND (val < limitp^) THEN
BEGIN { in range defined }
GetIndString(s, resid, val + 1);
PrintString(s);
err := FALSE;
END
END;
IF err THEN
PrintInt(val); { no string, show the integer }
END;
{ --------------- Format Rect ------------- }
PROCEDURE DumpRect; {(msg : Str255; r : Rect);}
BEGIN
PrintString(msg);
PrintString(': {');
PrintInt(r.top);
PrintString(', ');
PrintInt(r.left);
PrintString(', ');
PrintInt(r.bottom);
PrintString(', ');
PrintInt(r.right);
PrintString('}');
PrintLine;
END;
{ -------------- Format TPrInfo ----------- }
PROCEDURE DumpPrInfo; {(msg : Str255; prinf : TPrInfo);}
BEGIN
PrintString(msg);
PrintStrNum('iDev: ', prinf.iDev);
PrintStrNum('iVRes: ', prinf.iVRes);
PrintStrNum('iHRes: ', prinf.iHRes);
PrintLine;
DumpRect('rPage', prinf.rPage);
END;
{ ------------- Format TPrXInfo ------------- }
PROCEDURE DumpPrXInfo; {(msg : Str255; prxi : TPrXInfo);}
BEGIN
PrintString(msg);
PrintStrNum('iRowBytes: ', prxi.iRowBytes);
PrintStrNum('iBandH: ', prxi.iBandV);
PrintStrNum('iBandV: ', prxi.iBandH);
PrintLine;
PrintStrNum('iDevBytes: ', prxi.iDevBytes);
PrintStrNum('iBands: ', prxi.iBands);
PrintLine;
PrintStrNum('bPatScale: ', prxi.bPatScale);
PrintStrNum('bUlThick: ', prxi.bUlThick);
PrintStrNum('bUlOffset: ', prxi.bUlOffset);
PrintStrNum('bUlShadow: ', prxi.bUlShadow);
PrintLine;
DumpEnum('scan: ', ORD(prxi.scan), STRN_scan);
PrintStrNum('bXInfoX: ', prxi.bXInfoX);
PrintLine;
END;
{ ------------- Format TPrStl ------------ }
PROCEDURE DumpPrStl; {( msg : Str255;ps : TPrStl);}
BEGIN
PrintString(msg);
PrintStrHex('wDev: $', ps.wDev, 4);
DumpEnum('(', BitShift(ps.wDev, -8), STRN_wdev);{device code}
PrintString(')');
PrintLine;
PrintStrNum('iPageV: ', ps.iPageV);
PrintStrNum('iPageH: ', ps.iPageH);
PrintStrNum('bPort: ', ps.bPort);
DumpEnum('feed: ', ORD(ps.feed), STRN_feed);
PrintLine;
END;
{ ------------- Format TPrJob ------------- }
PROCEDURE DumpPrJob; {(msg : Str255; pj : TPrJob);}
BEGIN
PrintString(msg);
PrintStrNum('iFstPage: ', pj.iFstPage);
PrintStrNum('iLstPage: ', pj.iLstPage);
PrintStrNum('iCopies: ', pj.iCopies);
DumpEnum('bJDocLoop: ', ORD(pj.bJDocLoop), STRN_job);
PrintLine;
DumpEnum('fFromUsr: ', ORD(pj.fFromUsr), STRN_bool);
PrintStrHex('pIdleProc: ', ORD4(pj.pIdleProc), 8);
PrintStrHex('pFileName ', ORD4(pj.pFileName), 8);
PrintLine;
PrintStrNum('iFileVol: ', pj.iFileVol);
PrintStrNum('pFileVers: ', pj.bFileVers);
PrintStrNum('bJobX: ', pj.bJobX);
PrintLine;
END;
{ ------------ Format printX Array ---------- }
PROCEDURE DumpPrintX; {( msg : Str255;tpp : TPPrin );}
VAR
i, max : INTEGER;
BEGIN { Outputs non-zero values, if any; ignore trailing run of zero}
max := 0;
FOR i := 1 TO 19 DO
IF (tpp^.printX[i] <> 0) THEN
max := i; { ignore trailing zeroes }
IF (max > 0) THEN
BEGIN
PrintString(msg);
FOR i := 1 TO max DO
BEGIN
PrintStrNum('[', i);
PrintString(']: ');
PrintHex(tpp^.printX[i], 4);
IF (((i MOD 4) = 0) OR (i = max)) THEN
PrintLine; { every 4th or last one }
END
END
END;
{ -------------- Format TPrint ------------ }
PROCEDURE DumpPrint; {(msg : Str255;hand : THPrint);}
VAR
tpp : TPPrint;
i : INTEGER;
BEGIN
HLock(Handle(hand));
tpp := hand^; { pointer to a TPrint }
PrintLine;
PrintString(msg);
PrintLine;
FOR i := 1 TO Length(msg) DO
PrintString('-');
PrintLine;
PrintString('iPrVersion: ');
PrintInt(tpp^.iPrVersion);
PrintLine;
DumpPrInfo('prInfo', tpp^.prInfo);
DumpRect('rPaper', tpp^.rPaper);
DumpPrStl('prStl', tpp^.prStl);
DumpPrInfo('prInfoPT', tpp^.prInfoPT);
DumpPrXInfo('prXInfo', tpp^.prXInfo);
DumpPrJob('prJob', tpp^.prJob);
DumpPrintX('printX', tpp);
PrintString('------------------------------------------------------------------------------');
PrintLine;
HUnLock(Handle(hand));
END; {DumpPrint}
END.